import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

# 打开浏览器,窗口最大化
driver = webdriver.Chrome()
driver.maximize_window()

# 请求网页,定位到下拉框
driver.get('https://sahitest.com/demo/selectTest.htm')
s1 = driver.find_element(By.ID, 's1')

# 创建Select对象,然后实例化
select = Select(s1)  # 注意要传入元素

# 通过索引选取
select.select_by_index(2)
time.sleep(3)

# 通过value值选取
select.select_by_value('49')
time.sleep(3)

# 通过文本选取
select.select_by_visible_text('Mail')
time.sleep(3)

# 关闭浏览器
driver.quit()